package com.bank.controller;


import com.bank.constant.AccountStatus;
import com.bank.constant.MessageConstant;
import com.bank.dto.AccountStatusTransferDTO;
import com.bank.result.Result;
import com.bank.service.AccountStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Objects;

@CrossOrigin
@RestController
@RequestMapping("/status")
@Slf4j
@Api(tags = "4.账户状态管理")
public class AccountStatusController {
    @Autowired
    private AccountStatusService accountStatusService;

    @PostMapping("/loss")
    @ApiOperation("账户状态更改")
    public Result<String> changeStatus(@RequestBody @Valid AccountStatusTransferDTO accountStatusTransferDTO) {
        log.info("开始执行账户状态更改接口");
        accountStatusService.changeStatus(accountStatusTransferDTO);
        // TODO 增加短信通知
        String msg = Objects.equals(accountStatusTransferDTO.getStatus(), AccountStatus.FROZEN) ? MessageConstant.FREEZE_SUCCESS :
                Objects.equals(accountStatusTransferDTO.getStatus(), AccountStatus.LOST) ? MessageConstant.LOSS_SUCCESS :
                        MessageConstant.CLOSE_SUCCESS;

        return Result.success(msg);
    }
}
